class ReposHooks
  attr_accessor :github

  def initialize(github)
    @github = github
  end

  def listHooks(repo, user=nil)
    username = user == nil ? @github.username : user
    @github.get('repos/%s/%s/hooks' % [username, repo])
  end

  def getHook(repo, id, user=nil)
    username = user == nil ? @github.username : user
    @github.get('repos/%s/%s/hooks/%s' % [username, repo, id])
  end

  def createHook(repo, name, config, events=nil, active=TRUE,
      user=nil)
    username = user == nil ? @github.username : user
    params = {
        :name => name,
        :config => config,
        :events => events,
        :active => active
    }
    params = @github.removeEmptyParams(params)
    data = params.to_json
    @github.post('repos/%s/%s/hooks' % [username, repo], data)
  end

  def editHook(repo, id, name, config, events=nil, add_events=nil,
      remove_events=nil, active=TRUE, user=nil)
    username = user == nil ? @github.username : user
    params = {
        :name => name,
        :config => config,
        :events => events,
        :add_events => add_events,
        :remove_events => remove_events,
        :active => active
    }
    params = @github.removeEmptyParams(params)
    data = params.to_json
    @github.patch('repos/%s/%s/hooks/%s' % [username, repo, id], data)
  end

  def testHook(repo, id, user=nil)
    username = user == nil ? @github.username : user
    @github.post('repos/%s/%s/hooks/%s/test' % [username, repo, id])
  end

  def deleteHook(repo, id, user=nil)
    username = user == nil ? @github.username : user
    @github.delete('repos/%s/%s/hooks/%s' % [username, repo, id])
  end
end